package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/7/22 11:02
 * @apiNote
 */

public class Test00997FindJudge {

    public static void main(String[] args) {
        int n =3;

        int[][] trust = {{1,3},{2,3}};
        int res = findJudge(n, trust);
        System.out.println(res);
    }

    public static int findJudge(int n, int[][] trust) {
        int[] inDegrees = new int[n + 1];
        int[] outDegrees = new int[n + 1];
        for(int[] edge : trust){
            int x = edge[0],y = edge[1];
            inDegrees[y]++;
            outDegrees[x]++;
        }
        for(int i = 1;i<=n;i++){
            if(inDegrees[i] == n-1 && outDegrees[i] == 0){
                return i;
            }
        }
        return -1;
    }
}
